package com.fz.us.oa.web.controller.main.dict;

import com.fz.us.admin.base.bean.Result;
import com.fz.us.admin.company.entity.Company;
import com.fz.us.admin.company.entity.User;
import com.fz.us.admin.dict.entity.Dict;
import com.fz.us.admin.dict.service.DictService;
import com.fz.us.oa.web.controller.BaseController;
import com.fz.us.oa.web.shiro.bind.annotation.CurrentUser;
import org.springframework.http.MediaType;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;

/**
 * 控制器 - Dict
 * ============================================================================
 * 版权所有 2016 。
 *
 * @version 1.0 2016-08-03 。
 * ============================================================================
 */
@Controller
@RequestMapping(value = "/main/dict_user")
public class CustomDictController extends BaseController {

    private static final long serialVersionUID = -8272015173389962341L;

    @Resource
    private DictService dictService;

    /**
     * 列表
     */
    @RequestMapping(value = "list", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
    public Object list(@CurrentUser User user){
        Company company = user.getCompany();

        List<Dict> dictList = dictService.listDefault(company.getId());
        ArrayList<Map<String, Object>> dataRows = new ArrayList<Map<String, Object>>();

        for (Dict entity : dictList) {
            Map<String, Object> map = dictService.getListMap(entity);
            dataRows.add(map);
        }

        return ajaxJson(resultService.successWithData(dataRows));
    }

}
